package com.itheima.Controller;

import com.itheima.Service.ClazzService;
import com.itheima.pojo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;


@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;


    @GetMapping
//        public Result page(String name ,
//                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin ,
//                      @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
//                      @RequestParam(defaultValue = "1") Integer page ,
//                       @RequestParam(defaultValue = "10") Integer pageSize){
//        log.info("查询员工信息, page={}, pageSize={}", page, pageSize);
//        PageBean pageBean = clazzService.page(name,begin,end,page, pageSize);
//        return Result.success(pageBean);
//    }
public Result page(ClazzQueryParam param) {
    log.info("请求参数： {}", param);
    PageBean pageBean = clazzService.page(param);
    return Result.success(pageBean);
}

    @PostMapping
    public Result save(@RequestBody Clazz clazz) {
        log.info("新增部门:{}", clazz);
        System.out.println("新增部门:" + clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工的详细信息");
        Clazz clazz  = clazzService.getInfo(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改部门:{}", clazz);
        clazzService.update(clazz);

        return Result.success();
    }
    //查询所有班级
    @GetMapping("/list")
    public Result list(){
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }

}
